<template>
  <div style="width: 100%;box-sizing: border-box;overflow: auto;height: 85vh;">
      <el-row>
        <el-col :span="24" style="line-height: 40px;margin-bottom: 5px;">
<!--          年份：-->
                      <el-date-picker v-model="examineYear" style="width: 200px;" value-format="YYYY"
                                      type="year" placeholder="请选择年份" @change="getList">
                      </el-date-picker>
          <el-button type="primary" @click="getList">查询</el-button>
          <el-button type="warning" plain @click="exportData">导出</el-button>
        </el-col>
      </el-row>
    <el-table
      :data="tableData"
      border stripe
      size="default"
      height="80vh"
      highlight-current-row
    >
      <!-- 序号 -->
      <el-table-column align="center" prop="supervisoryUnit" label="序号" width="60" fixed>
        <template #default="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <!-- 业务主管单位 -->
      <el-table-column align="center" prop="supervisoryUnit" label="业务主管单位" width="200" fixed :show-overflow-tooltip="true"/>
      <!-- 年度检查 -->
      <el-table-column align="center" label="年度检查">
        <el-table-column align="center" prop="annualCount" label="应检数" width="70" />
        <el-table-column align="center" prop="joinCount" label="参检数" width="70" />
        <el-table-column align="center" prop="annualRate" label="年检率" width="70">
          <template #default="scope">
            <span>{{ (scope.row.annualRate * 100).toFixed(0) + '%' }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="passCount" label="合格数" width="70" />
        <el-table-column align="center" prop="passRate" label="合格率" width="70" >
          <template #default="scope">
            <span>{{ (scope.row.passRate * 100).toFixed(0) + '%' }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="timelyCount" label="按时办结数" width="70" />
        <el-table-column align="center" prop="timelyRate" label="按时办结率" width="70">
          <template #default="scope">
            <span>{{ (scope.row.timelyRate * 100).toFixed(0) + '%' }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="avgTimely" label="平均办结时间" width="150" />

      </el-table-column>

      <!-- 党建工作 -->
      <el-table-column align="center" label="党建工作">
        <el-table-column align="center" prop="partyOrganizationCount" label="建立党组织数" width="70" >
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.partyOrganizationCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="socialOrganizationCount" label="建立群团组织数" width="70" >
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.socialOrganizationCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="guideCount" label="有党建指导员数" width="70">
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.guideCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="coverageRate" label="党建覆盖率" width="70" >
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;"><span>{{ (scope.row.coverageRate * 100).toFixed(0) + '%' }}</span></div>
          </template>
        </el-table-column>
      </el-table-column>

      <!-- 财务管理 -->
      <el-table-column align="center" label="财务管理">
        <el-table-column align="center" prop="balanceCount" label="年末资金小于开办资金数" width="90" />
        <el-table-column align="center" prop="accountantCount" label="有专业会计数" width="70" />
        <el-table-column align="center" prop="financeCount" label="财务制度健全数" width="70" />
      </el-table-column>

      <!-- 活动开展 -->
      <el-table-column align="center" label="活动开展">
        <el-table-column align="center" prop="organizationCount" label="当年开展活动组织数" width="80" >
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.organizationCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="activityCount" label="当年开展活动总数" width="70">
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.activityCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="averageActivityCount" label="年平均开展活动数" width="70">
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ scope.row.averageActivityCount }}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="activityCoverageRate" label="活动覆盖度" width="70" >
          <template #default="scope">
            <div style="background-color:rgba(111,111,111,0.15);padding: 5px 10px 5px 10px;">{{ (scope.row.activityCoverageRate * 100).toFixed(2) }}%
            </div>
          </template>
        </el-table-column>
      </el-table-column>

      <!-- 综合评价 -->
      <el-table-column align="center" label="综合评价">
        <el-table-column align="center" prop="evaluationCount" label="优秀（100分以上）" width="90" />
        <el-table-column align="center" prop="goodEvaluationCount" label="良好（80-99分）" width="70" />
        <el-table-column align="center" prop="standardEvaluationCount" label="达标（60-79分）" width="70" />
        <el-table-column align="center" prop="poorEvaluationCount" label="较差（60分以下）" width="70" />
        <el-table-column align="center" prop="standardRate" label="达标率" width="70">
          <template #default="scope">
            <span>{{ (scope.row.standardRate * 100).toFixed(0) + '%' }}</span>
          </template>
        </el-table-column>
      </el-table-column>

      <!-- 备注 -->
      <!--    <el-table-column align="center" prop="remark" label="备注" width="150" />-->
    </el-table>
  </div>
</template>

<script setup>
import {onMounted, onUnmounted, ref,getCurrentInstance} from "vue";
import { getAuthorityDept, getCountByYear } from '@/views/yearCheck/ykb/mf/mf'
import { exportYearData } from '@/views/yearCheck/ykb/otherApi'
import { modelValue } from '@/views/yearCheck/checkResult/components/comTime/config'

const tableData = ref([]);
const examineYear = ref(new Date().getFullYear() - 1 + '')
function getList(){
  // 获取数据new Date().getFullYear()
  console.log(examineYear.value)
  if(examineYear.value){
    getCountByYear(examineYear.value).then(response => {
      tableData.value = response.data;
    });
  }else{
    getCountByYear(new Date().getFullYear()).then(response => {
      tableData.value = response.data;
    });
  }

}
getList();

function exportData(){
  exportYearData(examineYear.value).then(res => {
    const blob = new Blob([res], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    })
    const a = document.createElement('a')
    const URL = window.URL || window.webkitURL
    const herf = URL.createObjectURL(blob)
    a.href = herf
    a.download = examineYear.value + '年检统计.xlsx'
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    window.URL.revokeObjectURL(herf)
  })
}
</script>

<style scoped lang="scss">
//.complex-table .el-table__header-wrapper th {
//  background-color: #f5f7fa;
//  white-space: nowrap;
//}
//.el-table__body-wrapper {
//  overflow-x: auto;
//}
:deep(.el-table--enable-row-transition .el-table__body td.el-table__cell) {
  padding:0px !important;
}
:deep(.el-table--default .cell){
  padding:0px !important;
}
</style>
